package Collections_ArrayList_stu;

import java.util.*;

public class Collections_ArrayList_stu {

	public static void main(String[] args) {

		Stu s1 = new Stu("吴彦祖", 11);
		Stu s2 = new Stu("陈冠希", 12);
		Stu s3 = new Stu("周杰伦", 12);

		ArrayList<Stu> S = new ArrayList<Stu>();

		S.add(s3);
		S.add(s2);
		S.add(s1);

		Collections.sort(S, new Comparator<Stu>() {

			@Override
			public int compare(Stu o1, Stu o2) {
				int num = o1.getAge() - o2.getAge();
				int num2 = o1.getName().compareTo(o2.getName());

				if (num == 0) {
					return num2;
				}
				return num;
			}

		});
		for(int i=0;i<S.size();i++) {
			System.out.println(S.get(i).getName()+","+S.get(i).getAge());
		}
		
		for(Stu s : S) {
			System.out.println(s.getName()+","+s.getAge());
		}

	}

}
